﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using Spring.Context;
using Gestion.Core.Data;
using Gestion.Core.Service;

namespace Gestion.Ui
{
    public class ApplicationModule : IHttpModule
    {
        private static Object lck = new Object();

        private static IApplicationContext _applicationContext = null;
        public static IApplicationContext ApplicationContext
        {
            get { return ApplicationModule._applicationContext; }
            set { ApplicationModule._applicationContext = value; }
        }

        public ApplicationModule()
        {
            lock (lck)
            {
                if (ApplicationModule.ApplicationContext == null)
                {
                    Gestion.Config.AppConfigurator.ConfigureLog4net();
                    ApplicationModule.ApplicationContext = Gestion.Config.AppConfigurator.ConfigureApplicationContext();
                }
            }
        }

        public static ServiceManager getServiceManager()
        {            
            return (ServiceManager)ApplicationModule.ApplicationContext["serviceManager"];
        }
        public static ServiceManager GetPlainServiceManager()
        {
            return (ServiceManager)ApplicationModule.ApplicationContext["plainServiceManager"];            
        }



        #region Miembros de IHttpModule

        public void Dispose() { }

        public void Init(HttpApplication context){ }        

        #endregion
    }
}
